#include "common.h"
QMap  <tcp_socket*,M_Socket*>  Common::tcp_server_SocketMap;        //t_socket集合
QReadWriteLock   Common::tcp_server_SocketMapLock;                                 //t_socket读写锁
QMap<local_socket*,M_Socket*> Common::localSocket_Map;              //l_socketMAP
QReadWriteLock   Common::localSocket_MapLock;                                      //l_socket读写锁
QList<LocalSocket_SendData>      Common::Localsocket_unsenddata;                             //本地socket未发送的任务
QReadWriteLock   Common::Localsocket_unsenddataLock;                                 //本地socket未发送任务读写锁
QMap<QString,LocalSocket_SendData>      Common::Localsocket_Caculatedata;  //本地socket正在处理的任务
QReadWriteLock   Common::Localsocket_CaculatedataLock;               //本地socket正在处理任务锁
QStringList      Common::Logdata;                                    //日志内容
QReadWriteLock   Common::LogdataLock;                                //日志锁
QReadWriteLock   Common::ConfigureLock;                             //配置锁
QString          Common::Tcp_ip;                                     //连接tcp地址
int              Common::Tcp_port;                                   //tcp端口
QString          Common::LocalPort="localCaculate";                                  //本地监听端口
int              Common::Hand_Count;                                 //处理线程个数
int              Common::Caculate_Count;
bool             Common::Log_Open=true;                              //日志开启
int              Common::Log_Size=500;                               //日志大小
Common::Common()
{

}

M_Socket* Common::GetLocal_Socket()
{
    localSocket_MapLock.lockForRead();
    bool isempty=localSocket_Map.isEmpty();
    if (isempty)
    {
        localSocket_MapLock.unlock();
        return NULL;
    }
    QMap<local_socket*,M_Socket*>::const_iterator i=localSocket_Map.begin();
    localSocket_MapLock.unlock();
    return i.value();
}

M_Socket *Common::GetTcp_Socket()
{
    tcp_server_SocketMapLock.lockForRead();
    bool isempty=tcp_server_SocketMap.isEmpty();
    if (isempty)
    {
        tcp_server_SocketMapLock.unlock();
        return NULL;
    }
    QMap<tcp_socket*,M_Socket*>::const_iterator i=tcp_server_SocketMap.begin();
    tcp_server_SocketMapLock.unlock();
    return i.value();
}
